import Vue from 'vue'
import VueRouter from 'vue-router'
/* Layout */
import Layout from '@/layout'

Vue.use(VueRouter)

export const routes = [
  {
    path: '/login',
    name: 'Login',
    component: function () {
      return import('../views/login/index.vue')
    },
  },
  {
    path: '',
    component: Layout,
    redirect: 'index',
    children: [
      {
        path: 'index',
        component: (resolve) => require(['@/views/home/index'], resolve),
        name: '我的临床研究',
        meta: {
          title: '我的临床研究',
          icon: 'el-icon-s-management',
          keepAlive: '1',
        },
      },
      {
        path: '/allList',
        component: (resolve) => require(['@/views/allList/index'], resolve),
        name: '所有临床研究',
        meta: { title: '所有临床研究', icon: 'el-icon-menu', keepAlive: '1' },
      },
      {
        path: '/mine',
        component: (resolve) => require(['@/views/mine/index'], resolve),
        name: '个人中心',
        meta: { title: '个人中心', icon: 'el-icon-s-custom', keepAlive: '1' },
      },
    ],
  },
]

// 防止连续点击多次路由报错
let routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return routerPush.call(this, location).catch((err) => err)
}

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
})

export default router
